String label;
String prompt;
String message;

public class Temp {

    TreeNode newNode;

    private void getValidLine(BufferedReader reader) {
	if ((String temp = reader.readLine()) == null)
	    return temp;
	while (temp.equals(""))
	    temp = reader.readLine();
	return temp;
    }

    private boolean loadFile() {
	String fileName;
    	BufferedReader reader;

	String label;
	String prompt;
	String message;
    
	TreeNode activeParentNode;

 	System.out.print("Please enter the file name: ");
    	fileName = getInput();
    	if (!fileName.endsWith(".txt")){
    	    System.out.println("Selected file is not a text file. Please enter a valid text file.\n\nPress enter to continue.");
    	    getInput();
    	    return null;
    	} 

	try {
    	    reader = new BufferedReader(new FileReader(fileName));
    
	    if (tree == null) {
		if ((label = getValidLine(reader)) == null || !label.equals("root"))
		    return false;
		if ((prompt = getValidLine(reader)) == null)
		    return false;
		if ((message = getValidLine(reader)) == null)
		    return false;
		tree = new Tree(new TreeNode(label, prompt, message));
		activeParentNode = tree.getNodeReference("root");
	    }
   
	    while (true) {
		if (label = getValidLine(reader)) == null) 
		break;
		if (tree.getNodeReference(label.split(" ")[0]) == null) {           //if this node has not yet been defined
		    if ((prompt = getValidLine(reader)) == null)
			return false;
		    if ((message = getValidLine(reader)) == null)
			return false;
		    activeParentNode.addChild(new TreeNode(label, prompt, message));
		}
		else { //if this node has already been defined
		    activeParentNode = tree.getNodeReference(label.split(" ")[0]);
		}
	    }
	reader.close();
       }
   
catch(IOException e) {
	System.out.println("File input failed. Please check the file and try again.");
	return false;
    }
    return true;
}
}
   


}


